with newer stuff.
Fix loops that free ll elements.
Misc cleanups.
static btree_node *
addnode (btree_node * tree, btree_node * newnode, btree_node **oldnode)
{
- btree_node * tmp, * last;
+ btree_node * tmp, * last = NULL;
if ( *oldnode ) {*oldnode = NULL;}
mps_find_icon_number_from_desc(const char *desc,
garmin_formats_e garmin_format);
-
/* MapSource 4.13 */
static icon_mapping_t icon_table[] = {
/* mps pcx desc */
usage(argv[0]);
exit(0);
}
-
if (ovecs == NULL)
waypt_disp_all(waypt_disp);
static FILE *mapsend_file_out;
static void *mkshort_handle;
-static int endianness_tested;
-static int i_am_little_endian;
-
static int route_wp_count;
static int mapsend_infile_version;
static int trk_version = 30;
#define MYNAME "mapsend"
-static void
-test_endianness(void)
-{
- union {
- long l;
- unsigned char uc[sizeof (long)];
- } u;
-
- u.l = 1;
- i_am_little_endian = u.uc[0];
-
- endianness_tested = 1;
-
-}
-
static void
mapsend_rd_init(const char *fname)
{
}
static
-size_t
+void
my_fread8(void *ptr, FILE *stream)
{
unsigned char cbuf[8];
- unsigned char *cptr = ptr;
size_t rv;
- if (!endianness_tested) {
- test_endianness();
- }
-
- if (i_am_little_endian) {
- rv = fread(ptr, 8, 1, stream);
- } else {
- rv = fread(cbuf, 8, 1, stream);
- cptr[0] = cbuf[7];
- cptr[1] = cbuf[6];
- cptr[2] = cbuf[5];
- cptr[3] = cbuf[4];
- cptr[4] = cbuf[3];
- cptr[5] = cbuf[2];
- cptr[6] = cbuf[1];
- cptr[7] = cbuf[0];
- }
- return rv;
+ rv = fread(cbuf, 8, 1, stream);
+ le_read64(ptr, cbuf);
+
}
static
-size_t
+void
my_fwrite8(void *ptr, FILE *stream)
{
unsigned char cbuf[8];
- unsigned char *cptr = ptr;
- if (!endianness_tested) {
- test_endianness();
- }
-
- if (i_am_little_endian) {
- return fwrite(ptr, 8, 1, stream);
- } else {
- cbuf[0] = cptr[7];
- cbuf[1] = cptr[6];
- cbuf[2] = cptr[5];
- cbuf[3] = cptr[4];
- cbuf[4] = cptr[3];
- cbuf[5] = cptr[2];
- cbuf[6] = cptr[1];
- cbuf[7] = cptr[0];
- return fwrite(cbuf, 8, 1, stream);
- }
+ le_read64(cbuf, ptr);
+ fwrite(cbuf, 8, 1, stream);
}
static
-size_t
+void
my_fread4(void *ptr, FILE *stream)
{
+ unsigned int *iptr = ptr;
unsigned char cbuf[4];
- unsigned char *cptr = ptr;
size_t rv;
-
- if (!endianness_tested) {
- test_endianness();
- }
- if (i_am_little_endian) {
- rv = fread(ptr, 4, 1, stream);
- } else {
- rv = fread(cbuf, 4, 1, stream);
- cptr[0] = cbuf[3];
- cptr[1] = cbuf[2];
- cptr[2] = cbuf[1];
- cptr[3] = cbuf[0];
- }
- return rv;
+ rv = fread(cbuf, 4, 1, stream);
+ *iptr = le_read32(cbuf);
}
static
size_t
my_fwrite4(int *ptr, FILE *stream)
{
- unsigned char cbuf[4];
- unsigned char *cptr = (unsigned char *) ptr;
-
- if (!endianness_tested) {
- test_endianness();
- }
-
- if (i_am_little_endian) {
- return fwrite(ptr, 4, 1, stream);
- } else {
- cbuf[0] = cptr[3];
- cbuf[1] = cptr[2];
- cbuf[2] = cptr[1];
- cbuf[3] = cptr[0];
- return fwrite(cbuf, 4, 1, stream);
- }
+ int i = le_read32(ptr);
+ return fwrite(&i, 4, 1, stream);
}
static void
* we write mapsend v3.0 tracks as mapsend v2.0 tracks get
* tremendously out of whack time/date wise.
*/
- char *verstring;
+ char *verstring = "30";
queue *elem, *tmp;
char *tname;
unsigned char c;
char recType;
int reclen;
int reclen2;
- int tocopy;
+ unsigned int tocopy;
unsigned char copybuf[8192];
fclose(ofd);
}
-static void
-nav_waypt_pr(const waypoint *waypointp)
-{
-}
-
void
nav_write(void)
{
extern queue waypt_head;
-static double pos_dist;
static char *polyfileopt = NULL;
static char *exclopt = NULL;
#include "defs.h"
#include <ctype.h>
-#ifndef M_PI
-# define M_PI 3.14159265358979323846
-#endif
-
#define MYNAME "PSP"
#define MAXPSPSTRINGSIZE 256
static FILE *psp_file_out;
static FILE *mkshort_handle;
-static int i_am_little_endian;
-static int endianness_tested;
-
-static void
-test_endianness(void)
-{
- union {
- long l;
- unsigned char uc[sizeof (long)];
- } u;
-
- u.l = 1;
- i_am_little_endian = u.uc[0];
-
- endianness_tested = 1;
-
-}
-
static int
psp_fread(void *buff, size_t size, size_t members, FILE * fp)
{
unsigned char buf[8];
unsigned char sbuf[8];
- if (!endianness_tested) {
- test_endianness();
- }
-
- psp_fread(buf, 1, 8, psp_file_in);
- if (i_am_little_endian) {
- return *(double *) buf;
- }
- sbuf[0] = buf[7];
- sbuf[1] = buf[6];
- sbuf[2] = buf[5];
- sbuf[3] = buf[4];
- sbuf[4] = buf[3];
- sbuf[5] = buf[2];
- sbuf[6] = buf[1];
- sbuf[7] = buf[0];
- return *(double *)sbuf;
+ psp_fread(buf, 1, 8, fp);
+ le_read64(sbuf, buf);
+ return *(double *) sbuf;
}
static void
unsigned char *cptr = (unsigned char *)&x;
unsigned char cbuf[8];
- if (!endianness_tested) {
- test_endianness();
- }
- if (i_am_little_endian) {
- fwrite(&x, 8, 1, fp);
- } else {
- cbuf[0] = cptr[7];
- cbuf[1] = cptr[6];
- cbuf[2] = cptr[5];
- cbuf[3] = cptr[4];
- cbuf[4] = cptr[3];
- cbuf[5] = cptr[2];
- cbuf[6] = cptr[1];
- cbuf[7] = cptr[0];
- fwrite(cbuf, 8, 1, fp);
- }
-
+ le_read64(cbuf, cptr);
+ fwrite(cbuf, 8, 1, fp);
}
-#if 0
-static void
-psp_fwrite_word(unsigned int x, FILE *fp)
-{
- char *cptr = &x;
- char *cbuf[4];
-
- if (!endianness_tested) {
- test_endianness();
- }
- if (i_am_little_endian) {
- fwrite(&x, 4, 1, fp);
- } else {
- cbuf[0] = cptr[3];
- cbuf[1] = cptr[2];
- cbuf[2] = cptr[1];
- cbuf[3] = cptr[0];
- fwrite(cbuf, 4, 1, fp);
- }
-}
-#endif
-
/* Implement the grid in ascii art... This makes a bit of sense if you stand
on a point over the north pole and look down on the earth.
route_flush(queue *head)
{
queue *elem, *tmp;
- route_head *last = NULL;
-
+ queue *q;
+
QUEUE_FOR_EACH(head, elem, tmp) {
- if ( last ) {
- route_free(last);
- }
- last = (route_head *)elem;
- }
- if ( last ) {
- route_free(last);
+ q = dequeue(elem);
+ route_free((route_head *) q);
}
- QUEUE_INIT(head);
}
+
void
route_flush_all()
{
static FILE *tpg_file_out;
static void *mkshort_handle;
-static int i_am_little_endian;
-static int endianness_tested;
static unsigned int waypt_out_count;
-static void
-test_endianness(void)
-{
- union {
- long l;
- unsigned char uc[sizeof (long)];
- } u;
-
- u.l = 1;
- i_am_little_endian = u.uc[0];
-
- endianness_tested = 1;
-
-}
-
static int
tpg_fread(void *buff, size_t size, size_t members, FILE * fp)
{
unsigned char buf[8];
unsigned char sbuf[8];
- if (!endianness_tested) {
- test_endianness();
- }
-
tpg_fread(buf, 1, 8, fp);
- if (i_am_little_endian) {
- return *(double *) buf;
- }
- sbuf[0] = buf[7];
- sbuf[1] = buf[6];
- sbuf[2] = buf[5];
- sbuf[3] = buf[4];
- sbuf[4] = buf[3];
- sbuf[5] = buf[2];
- sbuf[6] = buf[1];
- sbuf[7] = buf[0];
+ le_read64(sbuf, buf);
return *(double *)sbuf;
}
unsigned char *cptr = (unsigned char *)&x;
unsigned char cbuf[8];
- if (!endianness_tested) {
- test_endianness();
- }
- if (i_am_little_endian) {
- fwrite(&x, 8, 1, fp);
- } else {
- cbuf[0] = cptr[7];
- cbuf[1] = cptr[6];
- cbuf[2] = cptr[5];
- cbuf[3] = cptr[4];
- cbuf[4] = cptr[3];
- cbuf[5] = cptr[2];
- cbuf[6] = cptr[1];
- cbuf[7] = cptr[0];
- fwrite(cbuf, 8, 1, fp);
- }
-
+ le_read64(cbuf, cptr);
+ fwrite(cbuf, 8, 1, fp);
}
static int
return tmp;
}
+
void
waypt_add(waypoint *wpt)
{
waypt_flush( queue *head )
{
queue *elem, *tmp;
- waypoint *last = NULL;
-
+
+ queue *q;
QUEUE_FOR_EACH(head, elem, tmp) {
- if ( last ) {
- waypt_free(last);
- }
- last = (waypoint *)elem;
- }
-
- if ( last ) {
- waypt_free(last);
+ q = dequeue(elem);
+ waypt_free((waypoint *) q);
}
-
- QUEUE_INIT(head);
}
+
void
waypt_flush_all()
{